<template>
  <div>
    <el-select
        v-model="tagFieldValue"
        placeholder="请选择"
        clearable
        @change="handleUpdateValue"
      >
        <el-option
          v-for="item in fieldOptions"
          :key="item.fieldName"
          :label="item.fieldShowName"
          :value="item.fieldName"
        >
        </el-option>
      </el-select>
  </div>
</template>
  
<script>
import { tagTableAndColumnConfigList } from "@/api/students/organization/consult";
import store from "@/store";
export default {
  name: "tagOperator",
  props: {
    value: {
      type: [String],
      default: null,
    },

    row: {
      type: Object,
      default: () => {},
    },
  },

  watch: {
    value(val) {
      this.tagFieldValue = val;
      console.log(this.tagFieldValue,"this.tagFieldValue");
    },
    row: {
      deep: true,
      handler(e) {
        const { tagField } = e;
        this.tagFieldValue = tagField;
      },
    },
    'row.tabName': {
      deep: true,
      handler(e) {
        const { tagField } = e;
        if(e) {
          this.fieldList(e);
        }
      },
    },
  },
  computed: {
    
  },

  data() {
    return {
      tagFieldValue: "",
      fieldOptions: [],
    };
  },

  mounted() {
    const { tagField = '', tabName } = this.row
    this.tagFieldValue = tagField
    if(tabName) {
      this.fieldList(tabName)
    }
  },
  methods: {
    // 字段
    fieldList(tabName) {
      const params = {
        userId: store.getters.user_id.toString(),
        userName: store.getters.userName.toString(),
        token: store.getters.token.toString(),
        type: "2",
        // 需要传tableNameList中的表名
        tableName: tabName ,
      };
      tagTableAndColumnConfigList(params).then((res) => {
        this.fieldOptions = res.resultdata;
      });
    },
    // 总的逻辑来处理数据
    handleUpdateValue(e) {
      console.log(e,"e");
      this.$emit("value", e);
      this.$emit("change", e);
    },
  },
};
</script>
  
  <style  scoped>
</style>